package com.xianyun.site.support.executor.handle.smtp.v20201108.config;


import com.xianyun.site.support.executor.handle.smtp.BaseSmtpStrategy;
import com.xianyun.site.support.executor.handle.smtp.v20201108.impl.ISmtpCheckStrategyImpl;
import com.xianyun.site.support.executor.handle.smtp.v20201108.impl.ISmtpConformStrategyImpl;
import com.xianyun.site.support.executor.handle.smtp.v20201108.impl.ISmtpResultStrategyImpl;

/**
 * 邮件发送类型
 * @author mac_zyj
 */

public enum  SmtpSendType {
    /**校验策略*/
    CHECK_TYPE("校验","1",new ISmtpCheckStrategyImpl()),
    /**结果策略*/
    RESULT_TYPE("结果","2",new ISmtpResultStrategyImpl()),
    /**推送策略*/
    PUSH_TYPE("推送","3",null),
    /**确认策略*/
    CONF_TYPE("确认","4",new ISmtpConformStrategyImpl()),
    /**默认策略*/
    OTHER("其他","5",null);
    /**类型名称*/
    private final String typeName;
    /**类型*/
    private final String type;
    /**策略*/
    private final BaseSmtpStrategy baseSmtpStrategy;

    SmtpSendType(String typeName, String type, BaseSmtpStrategy baseSmtpStrategy) {
        this.typeName = typeName;
        this.type = type;
        this.baseSmtpStrategy = baseSmtpStrategy;
    }

    public String getType() {
        return type;
    }

    public BaseSmtpStrategy getSmtpStrategy() {
        return baseSmtpStrategy;
    }

    public static Class<? extends  BaseSmtpStrategy> getSmtpStrategyByType(String type){
        for (SmtpSendType sendType:values()){
            if (sendType.getType().equals(type)){
                return sendType.getSmtpStrategy().getClass();
            }
        }
        return null;
    }

    public static SmtpSendType getSendTypeById(String type){
        for (SmtpSendType sendType:values()){
            if (sendType.getType().equals(type)){
                return sendType;
            }
        }
        return null;
    }
    public static String  getSendTypeNameById(String type){
        for (SmtpSendType sendType:values()){
            if (sendType.getType().equals(type)){
                return sendType.typeName;
            }
        }
        return null;
    }
}
